package com.project.ryudo.SessionBean;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Session Bean implementation class requestPropertyBean
 */
@Stateless
@LocalBean
public class requestPropertyBean implements requestPropertyBeanRemote {

    /**
     * Default constructor. 
     */
	@PersistenceContext
	EntityManager em;
    public requestPropertyBean() {
        // TODO Auto-generated constructor stub
    }
	@Override
	public List requestedProperty(String pid) {
		Query query = em.createQuery("select prop from Property prop where prop.propID = :propID");
		query.setParameter("propID", pid);
		List result = query.getResultList();
		return result;
	}
	@Override
	public List requestedPropertyType(String pid,String type) {
		String propType = null;
		if(type.equalsIgnoreCase("pfr"))
		{
			propType = "PropForRent";
		}
		else if(type.equalsIgnoreCase("pfs"))
		{
			propType = "PropForSale";
		} else if(type.equalsIgnoreCase("rfr"))
		{
			propType = "RoomForRent";
		}
		Query query = em.createQuery("select prop from "+propType+" prop where prop.propID = :propID");
		query.setParameter("propID", pid);
		List result = query.getResultList();
		return result;
	}
	@Override
	public List requestedAccount(int accid) {
		Query query = em.createQuery("select acc from Account acc where acc.accID = :accID");
		query.setParameter("accID", accid);
		List result = query.getResultList();
		return result;
	}
	@Override
	public List requestedImages(String pid) {
		Query query = em.createQuery("select imgs from Property_Image imgs where imgs.property.propID = :propID");
		query.setParameter("propID", pid);
		List result = query.getResultList();
		return result;
	}

}
